package com.weiz.apigen;

import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
public class EntityA {
    /**
     * EntityA的 groupId
     */
    @SerializedName("group_id")
    private Integer groupId;
    private String name;

    private List<EntityA1> listA1;

    @Getter
    @Setter
    //static class
    /*
将内部类改为静态内部类（改变类结构的方式）
如果业务逻辑允许，可以把非静态内部类改为静态内部类。静态内部类不依赖于外部类的实例，它可以像普通类一样被实例化，只是在访问外部类的成员时有一定限制（只能访问外部类的静态成员）。示例如下：
class OuterClass {
    private int outerValue;

    static class InnerClass {
        private int innerValue;
    }
}
改为静态内部类后，Jackson 在进行反序列化时就不会受到非静态内部类实例化规则的限制了，但要确保代码中对原来内部类访问外部类实例相关逻辑进行相应调整，因为静态内部类不再持有外部类实例的引用了。

    *2025-01-02 13:42:00.388 ERROR 21104 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class com.weiz.apigen.EntityA$EntityA1]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.weiz.apigen.EntityA$EntityA1`: non-static inner classes like this can only by instantiated using default, no-argument constructor
 at [Source: (PushbackInputStream); line: 8, column: 18] (through reference chain: com.weiz.apigen.MyClass["listEntityA"]->java.util.ArrayList[0]->com.weiz.apigen.EntityA["listA1"]->java.util.ArrayList[0])] with root cause

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.weiz.apigen.EntityA$EntityA1`: non-static inner classes like this can only by instantiated using default, no-argument constructor
 at [Source: (PushbackInputStream); line: 8, column: 18] (through reference chain: com.weiz.apigen.MyClass["listEntityA"]->java.util.ArrayList[0]->com.weiz.apigen.EntityA["listA1"]->java.util.ArrayList[0])
	at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67) ~[jackson-databind-2.11.0.jar:2.11.0]
    * */
    public static class EntityA1 {
        @SerializedName("group_id")
        private Integer groupId;
        /**
         * EntityA1的 name
         */
        private String name;
    }
}